package com.hongning.railway.ui.main.fragments.college.itemviewModel;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hongning.railway.R;
import com.hongning.railway.entity.resbean.Fileterbean;

import java.util.List;

public class CollegeFilterItemAdapter extends BaseQuickAdapter<Fileterbean.ChildDataBean, BaseViewHolder> {
    boolean isRadioSelect=true;//是否是单选，默认是
    int  selectIndex=-1;//默认选中
    public CollegeFilterItemAdapter(@Nullable List<Fileterbean.ChildDataBean> data) {
        super(R.layout.collegefileter_item_item,data);
    }

    public boolean isRadioSelect() {
        return isRadioSelect;
    }

    public void setRadioSelect(boolean radioSelect) {
        isRadioSelect = radioSelect;
    }

    public int getSelectIndex() {
        return selectIndex;
    }

    public void setSelectIndex(int selectIndex) {
        this.selectIndex = selectIndex;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, Fileterbean.ChildDataBean item) {
           helper.setText(R.id.collegefileter_item_item_content,item.getTitle());
        if (isRadioSelect)
        {
            if (helper.getPosition()==selectIndex)
            {
                helper.<ImageView>getView(R.id.collegefileter_item_item_img).setVisibility(View.VISIBLE);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setBackgroundResource(R.drawable.button_red_bg);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setTextColor(mContext.getResources().getColor(R.color.color_C7301F));
            }else {
                helper.<ImageView>getView(R.id.collegefileter_item_item_img).setVisibility(View.GONE);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setBackgroundResource(R.drawable.button_gray_bg);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setTextColor(mContext.getResources().getColor(R.color.color_666666));


            }
        }else {
            if (item.isSelect())
            {
                helper.<ImageView>getView(R.id.collegefileter_item_item_img).setVisibility(View.VISIBLE);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setBackgroundResource(R.drawable.button_red_bg);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setTextColor(mContext.getResources().getColor(R.color.color_C7301F));

            }else {
                helper.<ImageView>getView(R.id.collegefileter_item_item_img).setVisibility(View.GONE);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setBackgroundResource(R.drawable.button_gray_bg);
                helper.<TextView>getView(R.id.collegefileter_item_item_content).setTextColor(mContext.getResources().getColor(R.color.color_666666));

            }
        }
           helper.itemView.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   if (isRadioSelect)
                   {
                       selectIndex=helper.getPosition();
                   }else {
                       item.setSelect(!item.isSelect());
                   }

                   notifyDataSetChanged();
               }
           });
    }
}
